package com.ayh.campusfun.common.core.config;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * @author ayh
 * @create 2021/3/24 0024 10:41
 * 异常状态码配置类，读取异常码配置文件数据
 */

// 关联配置文件
@PropertySource(value = "classpath:config/exception-code.properties")
// 指定配置文件的前缀为fun
@ConfigurationProperties(prefix = "fun")
@Component
@Data
public class ExceptionCodeConfiguration {

//    codes 与fun.codes中的codes相对应
    private Map<Integer, String> codes = new HashMap<Integer, String>();

    public String getMessage(Integer code){
        return codes.get(code);
    }
}
